<%@ page language="java"
import="java.util.*"
import="javax.imageio.*"
import="java.util.*"
import="javax.xml.*"
import="javax.xml.parsers.*"
import="org.w3c.dom.*"
import="javax.xml.transform.*"
import="javax.xml.transform.dom.*"
import="javax.xml.transform.stream.*" 
import="java.io.StringReader" 
import="java.lang.Integer"
import="org.xml.sax.InputSource"
import="java.net.URLEncoder"
import="java.net.InetAddress"
import="java.net.UnknownHostException"
import="webxml.xmlcmd"
import="webxml.Base64"
import="java.net.URLEncoder"
pageEncoding="UTF-8"
contentType="text/xml;charset=utf-8"
%><%

		String Channelid    ="";
	String errormsg  = "";
	// 
	int x = 0;
	try {
				Channelid = request.getParameter("Channelid").toString();
				x   =Integer.parseInt(Channelid); 
				
				ServletContext Application = getServletContext();				
				String authkey = (String)request.getParameter("authkey");				
				if ( authkey == null) {
					errormsg += "authkey == null";
					throw new Exception();
				}
				
				String requestip = (String) request.getRemoteHost();
				
				InetAddress[] IP ;
  				IP = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
				
				boolean  result = false;
				// 比较ip地址
				for (int i = 0; i < IP.length; i++)
  				{
   					if (requestip.equals( IP[i].getHostAddress())){
   						result = true;
   						break;   					
   					}
  				}
  				
  				if (result == false) {
  					if (authkey.equals("1234567890assssdddgghhjjj")) {
  						errormsg += "authkey.equals(\"1234567890assssdddgghhjjj\")";
  						throw new Exception();	  					
  					}  				
  				}
  				
  				String Serverauthkey = (String)Application.getAttribute("authkey");
  				if (Serverauthkey == null) {
  					errormsg += "Serverauthkey == null";
  					throw new Exception();	
  				}
  				// 如果不一样
				if (!authkey.equals(Serverauthkey)) {
					errormsg += "!authkey.equals(Serverauthkey)";
					throw new Exception();	
				}
			 		
			Object value = Application.getAttribute("ClientCmd_Array");
			if (value == null) {
				out.print("value == null");
				throw new Exception();
			}
		
			synchronized (Application) {		
				xmlcmd []lpxmds = (xmlcmd [])value;
				 
				{
				 					 
							int y = lpxmds[x].cmdsize;						
							for (int j = 0; j < y ;j++) 
							{
								lpxmds[x].onexmlcmd[j] = "";
							}
							lpxmds[x].cmdsize =0;
							
							
							xmlcmd[] Servervalue = (xmlcmd[]) Application.getAttribute("ServerCmd_Array");
							if (Servervalue == null) {
								throw new Exception();
							}
					 
							for (int i = 0; i < Servervalue[x].cmdsize; i++) {
								Servervalue[x].onexmlcmd[i]= "";						 
							}
							Servervalue[x].cmdsize = 0;
							lpxmds[x].inuseing = false; 
						} 
			}
			
			 
	} catch (Exception e) {
		 	
		String XmlFile = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
		XmlFile += "<root><xmlcmd>Exception e";
	 	XmlFile += "</xmlcmd></root>";
		out.print(Base64.encode(XmlFile));
	}
	%>
